data <-read.csv("Chlamydia - Rates of Reported Cases by County United States 2021 .csv")
Visualizations
Code
library(sf)library(ggplot2)library(dplyr)library(ggiraph)data <-read.csv("Chlamydia - Rates of Reported Cases by County United States 2021 .csv", header =TRUE)data$Rate <-as.numeric(data$Rate)
Warning: NAs introduced by coercion
Code
invisible({ us_counties <- tigris::counties(cb =TRUE, resolution ="20m", year =2020, class ="sf")})
Warning in sf_column %in% names(g): Detected an unexpected many-to-many relationship between `x` and `y`.
ℹ Row 1 of `x` matches multiple rows in `y`.
ℹ Row 65 of `y` matches multiple rows in `x`.
ℹ If a many-to-many relationship is expected, set `relationship =
"many-to-many"` to silence this warning.
Code
us_counties_data$Rate <-as.numeric(us_counties_data$Rate)us_counties_data_contiguous <- us_counties_data %>%filter(!(STATEFP %in%c("02", "15", "60", "66", "69", "72", "78")) )my_colors <-c('blue', 'purple', 'red', 'orange', 'yellow')gg <-ggplot() +geom_sf_interactive(data = us_counties_data_contiguous, aes(fill = Rate, tooltip =paste(NAMELSAD, "<br>", "Rate:", Rate)), color ="grey", size =0.1) +scale_fill_gradientn(colors = my_colors, na.value ="grey70", name ="Rate") +labs(title ="Chlamydia Infection Rate by County 2021", caption ="Total infection rate by chlamydia by county") +theme_minimal() +theme(axis.text =element_blank(),axis.title =element_blank(),axis.ticks =element_blank(),panel.grid =element_blank(),plot.caption =element_text(hjust = .5, size =8, margin =margin(t =10, r =10)))ggiraph(code =print(gg))
Function `ggiraph()` is replaced by `girafe()` and will be removed soon.
Code
library(sf)library(ggplot2)library(dplyr)library(ggiraph)data2 <-read.csv("Gonorrhea - Rates of Reported Cases by County United States 2021 .csv", header =TRUE)data2$Rate <-as.numeric(data2$Rate)
Warning: NAs introduced by coercion
Code
invisible({ us_counties <- tigris::counties(cb =TRUE, resolution ="20m", year =2020, class ="sf")})us_counties_contiguous <- us_counties %>%filter(!(STATEFP %in%c("02", "15", "60", "66", "69", "72", "78")) )us_counties_data <-left_join(us_counties, data2, by =c("NAMELSAD"="County"))
Warning in sf_column %in% names(g): Detected an unexpected many-to-many relationship between `x` and `y`.
ℹ Row 1 of `x` matches multiple rows in `y`.
ℹ Row 65 of `y` matches multiple rows in `x`.
ℹ If a many-to-many relationship is expected, set `relationship =
"many-to-many"` to silence this warning.
Code
us_counties_data$Rate <-as.numeric(us_counties_data$Rate)us_counties_data_contiguous <- us_counties_data %>%filter(!(STATEFP %in%c("02", "15", "60", "66", "69", "72", "78")) )my_colors <-c('blue', 'purple', 'red', 'orange', 'yellow')gg <-ggplot() +geom_sf_interactive(data = us_counties_data_contiguous, aes(fill = Rate, tooltip =paste(NAMELSAD, "<br>", "Rate:", Rate)), color ="grey", size =0.1) +scale_fill_gradientn(colors = my_colors, na.value ="grey70", name ="Rate") +labs(title ="Gonorrhea Infection Rate by County 2021", caption ="Total infection rate by gonorrhea by county") +theme_minimal() +theme(axis.text =element_blank(),axis.title =element_blank(),axis.ticks =element_blank(),panel.grid =element_blank(),plot.caption =element_text(hjust = .5, size =8, margin =margin(t =10, r =10)))ggiraph(code =print(gg))
Function `ggiraph()` is replaced by `girafe()` and will be removed soon.
Code
library(sf)library(ggplot2)library(dplyr)library(ggiraph)data3 <-read.csv("Primary and Secondary Syphilis - Rates of Reported Cases by County United States 2021 .csv", header =TRUE)data3$Rate <-as.numeric(data3$Rate)
Warning: NAs introduced by coercion
Code
invisible({ us_counties <- tigris::counties(cb =TRUE, resolution ="20m", year =2020, class ="sf")})us_counties_contiguous <- us_counties %>%filter(!(STATEFP %in%c("02", "15", "60", "66", "69", "72", "78")) )us_counties_data <-left_join(us_counties, data3, by =c("NAMELSAD"="County"))
Warning in sf_column %in% names(g): Detected an unexpected many-to-many relationship between `x` and `y`.
ℹ Row 1 of `x` matches multiple rows in `y`.
ℹ Row 65 of `y` matches multiple rows in `x`.
ℹ If a many-to-many relationship is expected, set `relationship =
"many-to-many"` to silence this warning.
Code
us_counties_data$Rate <-as.numeric(us_counties_data$Rate)us_counties_data_contiguous <- us_counties_data %>%filter(!(STATEFP %in%c("02", "15", "60", "66", "69", "72", "78")) )my_colors <-c('blue', 'purple', 'red', 'orange', 'yellow')gg <-ggplot() +geom_sf_interactive(data = us_counties_data_contiguous, aes(fill = Rate, tooltip =paste(NAMELSAD, "<br>", "Rate:", Rate)), color ="grey", size =0.1) +scale_fill_gradientn(colors = my_colors, na.value ="grey70", name ="Rate") +labs(title ="Primary and Secondary Syphilis Infection Rate by County 2021", caption ="Total infection rate by Primary and Secondary Syphilis by county") +theme_minimal() +theme(axis.text =element_blank(),axis.title =element_blank(),axis.ticks =element_blank(),panel.grid =element_blank(),plot.caption =element_text(hjust = .5, size =8, margin =margin(t =10, r =10)))ggiraph(code =print(gg))
Function `ggiraph()` is replaced by `girafe()` and will be removed soon.
Conclusion
Source Code
---title: "Final Portfolio"subtitle: "STI Analysis"author: "Cody Appa"date: "05/04/2023"code-fold: truecode-tools: true---## Preamble## Data```{r}suppressPackageStartupMessages(library(tidyverse))suppressPackageStartupMessages(library(scales))library(tidyverse)library(dplyr)library(ggplot2)library(readxl)library(scales)library(rnaturalearth)library(rnaturalearthdata)library(sf)library(tigris)suppressPackageStartupMessages(library(tigris))#STIDictionary<-read_excel("STISheet.xlsx")#knitr::kable(STIDictionary)``````{r}data <-read.csv("Chlamydia - Rates of Reported Cases by County United States 2021 .csv")```## Visualizations```{r}library(sf)library(ggplot2)library(dplyr)library(ggiraph)data <-read.csv("Chlamydia - Rates of Reported Cases by County United States 2021 .csv", header =TRUE)data$Rate <-as.numeric(data$Rate)invisible({ us_counties <- tigris::counties(cb =TRUE, resolution ="20m", year =2020, class ="sf")})us_counties_contiguous <- us_counties %>%filter(!(STATEFP %in%c("02", "15", "60", "66", "69", "72", "78")) )us_counties_data <-left_join(us_counties, data, by =c("NAMELSAD"="County"))us_counties_data$Rate <-as.numeric(us_counties_data$Rate)us_counties_data_contiguous <- us_counties_data %>%filter(!(STATEFP %in%c("02", "15", "60", "66", "69", "72", "78")) )my_colors <-c('blue', 'purple', 'red', 'orange', 'yellow')gg <-ggplot() +geom_sf_interactive(data = us_counties_data_contiguous, aes(fill = Rate, tooltip =paste(NAMELSAD, "<br>", "Rate:", Rate)), color ="grey", size =0.1) +scale_fill_gradientn(colors = my_colors, na.value ="grey70", name ="Rate") +labs(title ="Chlamydia Infection Rate by County 2021", caption ="Total infection rate by chlamydia by county") +theme_minimal() +theme(axis.text =element_blank(),axis.title =element_blank(),axis.ticks =element_blank(),panel.grid =element_blank(),plot.caption =element_text(hjust = .5, size =8, margin =margin(t =10, r =10)))ggiraph(code =print(gg))``````{r}library(sf)library(ggplot2)library(dplyr)library(ggiraph)data2 <-read.csv("Gonorrhea - Rates of Reported Cases by County United States 2021 .csv", header =TRUE)data2$Rate <-as.numeric(data2$Rate)invisible({ us_counties <- tigris::counties(cb =TRUE, resolution ="20m", year =2020, class ="sf")})us_counties_contiguous <- us_counties %>%filter(!(STATEFP %in%c("02", "15", "60", "66", "69", "72", "78")) )us_counties_data <-left_join(us_counties, data2, by =c("NAMELSAD"="County"))us_counties_data$Rate <-as.numeric(us_counties_data$Rate)us_counties_data_contiguous <- us_counties_data %>%filter(!(STATEFP %in%c("02", "15", "60", "66", "69", "72", "78")) )my_colors <-c('blue', 'purple', 'red', 'orange', 'yellow')gg <-ggplot() +geom_sf_interactive(data = us_counties_data_contiguous, aes(fill = Rate, tooltip =paste(NAMELSAD, "<br>", "Rate:", Rate)), color ="grey", size =0.1) +scale_fill_gradientn(colors = my_colors, na.value ="grey70", name ="Rate") +labs(title ="Gonorrhea Infection Rate by County 2021", caption ="Total infection rate by gonorrhea by county") +theme_minimal() +theme(axis.text =element_blank(),axis.title =element_blank(),axis.ticks =element_blank(),panel.grid =element_blank(),plot.caption =element_text(hjust = .5, size =8, margin =margin(t =10, r =10)))ggiraph(code =print(gg))``````{r}library(sf)library(ggplot2)library(dplyr)library(ggiraph)data3 <-read.csv("Primary and Secondary Syphilis - Rates of Reported Cases by County United States 2021 .csv", header =TRUE)data3$Rate <-as.numeric(data3$Rate)invisible({ us_counties <- tigris::counties(cb =TRUE, resolution ="20m", year =2020, class ="sf")})us_counties_contiguous <- us_counties %>%filter(!(STATEFP %in%c("02", "15", "60", "66", "69", "72", "78")) )us_counties_data <-left_join(us_counties, data3, by =c("NAMELSAD"="County"))us_counties_data$Rate <-as.numeric(us_counties_data$Rate)us_counties_data_contiguous <- us_counties_data %>%filter(!(STATEFP %in%c("02", "15", "60", "66", "69", "72", "78")) )my_colors <-c('blue', 'purple', 'red', 'orange', 'yellow')gg <-ggplot() +geom_sf_interactive(data = us_counties_data_contiguous, aes(fill = Rate, tooltip =paste(NAMELSAD, "<br>", "Rate:", Rate)), color ="grey", size =0.1) +scale_fill_gradientn(colors = my_colors, na.value ="grey70", name ="Rate") +labs(title ="Primary and Secondary Syphilis Infection Rate by County 2021", caption ="Total infection rate by Primary and Secondary Syphilis by county") +theme_minimal() +theme(axis.text =element_blank(),axis.title =element_blank(),axis.ticks =element_blank(),panel.grid =element_blank(),plot.caption =element_text(hjust = .5, size =8, margin =margin(t =10, r =10)))ggiraph(code =print(gg))```## Conclusion